/*
* @Author: zhangfan
* @Date:   2017-06-04 19:54:30
* @Last Modified by:   anchen
* @Last Modified time: 2017-06-04 20:35:15
 */

package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
	"time"
	// "sync"
	// "math/rand"
)

const (
	MaxIdleConnections int = 20
	RequestTimeout     int = 5
)

func createHTTPClient() *http.Client {
	client := &http.Client{
		Transport: &http.Transport{
			MaxIdleConnsPerHost: MaxIdleConnections,
		},
		Timeout: time.Duration(RequestTimeout) * time.Second,
	}

	return client
}

func main() {
	url := "http://httpbin.org/user-agent"
	client := createHTTPClient()
	req, _ := http.NewRequest("GET", url, nil)
	req.Header.Set("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0")
	resp, err := client.Do(req)
	if err != nil {
		fmt.Println(err)
	}
	defer resp.Body.Close()
	body, _ := ioutil.ReadAll(resp.Body)
	fmt.Println(string(body))
}
